#include "../../inc/mos_string.h"


Void string_test();
Void sstring_test();

Void string_test()
{
    SPTR str2 = "11 @@@  @grq @@@  @@@  @@weq  @@@ @@@ a @@@ @@th @@@ @@@ we @@@ @@@ wqef @@@ @@11";
    SPTR strtok = "@@@";

    S32 toklen = str_stoken_count(str2, strtok);
    DEBUG ("string token len str2: %d \n =================== \n", toklen);

    SPPTR str3 = str_stoken(str2, strtok);
    if(str3 == NULL)
    {
        DEBUG ("The String has no token :  %s \n ",  strtok);
        return;
    }

    U32 i = 0;
    while (*(str3+i) != NULL)
    {
         DEBUG ("stoken: str3[%d]:  %s \n ", i, *(str3+i));
         i++;
    }

  S32 trimlen = 0;
  str_stoken_free(str3);

  S8 str[] = {' ','\r','\t','h','e','l','l','o',' ','w','o','r','l','d','\n','\r','\b','\0'};
   DEBUG ("string source: %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
        str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7],str[8],str[9],str[10],
        str[11],str[12],str[13],str[14],str[15],str[16],str[17]);

  trimlen = str_begain_trim(str);
  DEBUG ("str_begain_trim: %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
        str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7],str[8],str[9],str[10],
        str[11],str[12],str[13],str[14],str[15],str[16],str[17]);
  DEBUG ("str_begain_trim: trimlen = %d:  %s \n ",trimlen, (SPTR)&str[trimlen]);

  str_end_trim( (SPTR)&str[trimlen], strlen((SPTR)&str[trimlen]) );
  DEBUG ("str_end_trim: %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
        str[0],str[1],str[2],str[3],str[4],str[5],str[6],str[7],str[8],str[9],str[10],
        str[11],str[12],str[13],str[14],str[15],str[16],str[17]);

}

Void sstring_test()
{
  SPTR string = "hello worold! ";
  SPTR strpen = "老王是个流氓兔！";
  S32 ret = 0;

  SString *sstr = sstring_new(string);
  DEBUG("sstring_new: str = %s , sLen = %d , mSize = %d ", 
      sstr->str, sstr->sLen, sstr->mSize);
  sstring_free(sstr);

  sstr = sstring_new_sized(BUF_SIZE_10);
    DEBUG("sstring_new_sized: sLen = %d , mSize = %d ", 
      sstr->sLen, sstr->mSize);

  ret = sstring_scpy(sstr, string, strlen(string));
  DEBUG("sstring_scpy: ret = %d, str = %s , sLen = %d , mSize = %d ", 
      ret, sstr->str, sstr->sLen, sstr->mSize);

  sstring_append(sstr, strpen, strlen(strpen));
  DEBUG("sstring_append: str = %s , sLen = %d , mSize = %d ", 
       sstr->str, sstr->sLen, sstr->mSize);

  sstring_format(sstr, "你好:%s, 非常好: %d, good: %d", "老王",10012, 997);
  DEBUG("sstring_format: str = %s , sLen = %d , mSize = %d ", 
       sstr->str, sstr->sLen, sstr->mSize);

  sstring_append_format(sstr, "你好:%s, 流氓: %d, good: %d", "老王", 9527, 886);
  DEBUG("sstring_append_format: str = %s , sLen = %d , mSize = %d ", 
       sstr->str, sstr->sLen, sstr->mSize);

  sstring_free(sstr);

}


int main(int argc, char *argv[])
{

    util_alarm_assert(argc);
    util_alarm_assert(argv);

    string_test();
    sstring_test();
    return 0;
}
